/**
 * 移除子对象
 * 
 */
package com.addcn.common.utils
{
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.AVM1Movie;        
	public class RemoveAllChildren extends Object {
			public static function remove(child:DisplayObject, self:Boolean = false):void {
					var childArray:Array = new Array();
					function removeall(childs:DisplayObjectContainer):void {
							if (childs!=null) {
									childArray.push(childs);
									if (childs.numChildren > 0){
											for (var i:uint = 0; i < childs.numChildren; i++) {
													if (childs.getChildAt(i) is DisplayObjectContainer) {
															var dis:DisplayObjectContainer = childs.getChildAt(i) as DisplayObjectContainer;
															removeall(dis);
													} else {
															if (!(childs.getChildAt(i) is AVM1Movie)) childArray.push(childs.getChildAt(i) as DisplayObject);
													}
											}
									}
							}
							return;
					}
					removeall(child);
					if (!self) childArray.shift();
					for (var j:int = childArray.length-1; j>=0; j--){
							var displayObject:DisplayObject = childArray[j] as DisplayObject;
							try {
									displayObject.parent.removeChild(displayObject);
									displayObject = null;
							} catch (error:Error) {
									trace(displayObject+"显示对象不存在");
							}
					}
					return;
			}
	}
}
